package com.sale.system.dubbo;

import com.sale.common.core.domain.R;
import com.sale.common.core.utils.BeanCopyUtils;
import com.sale.system.api.RemoteSysSupplierService;
import com.sale.system.api.domain.dto.SysCustomerBalance;
import com.sale.system.api.domain.dto.SysApiOrderSupplierManagementDto;
import com.sale.system.domain.dto.SysOrderSupplierManagementDto;
import com.sale.system.service.SysOrderSupplierManagementService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 供应商dubbo服务接口
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteSysSupplierServiceImpl implements RemoteSysSupplierService {


    private final SysOrderSupplierManagementService sysOrderSupplierManagementService;


    /**
     * 获取供应商详情
     * @param id
     * @return
     */
    @Override
    public R<SysApiOrderSupplierManagementDto> view(Long id) {
        SysApiOrderSupplierManagementDto supplierById = sysOrderSupplierManagementService.getSupplierById(id);
        SysApiOrderSupplierManagementDto sysApiOrderSupplierManagementDto = new SysApiOrderSupplierManagementDto();
        BeanCopyUtils.copy(supplierById, sysApiOrderSupplierManagementDto);
        return R.ok(sysApiOrderSupplierManagementDto);
    }

    /**
     * 通过编码获取供应商详情
     * @param code
     * @return
     */
    @Override
    public R<SysApiOrderSupplierManagementDto> getSupplierByCode(String code) {
        SysApiOrderSupplierManagementDto supplierByCode = sysOrderSupplierManagementService.getSupplierByCode(code);
        SysApiOrderSupplierManagementDto sysApiOrderSupplierManagementDto = new SysApiOrderSupplierManagementDto();
        BeanUtils.copyProperties(supplierByCode, sysApiOrderSupplierManagementDto);
        return R.ok(sysApiOrderSupplierManagementDto);
    }

    /**
     *  获取启用供应商（财务模块调用）
     * @return
     */
    @Override
    public Map<String, String> getOpenSupplierFinance() {
        return sysOrderSupplierManagementService.getOpenSupplierFinance();
    }

    /**
     * 通过供应商名称获取供应商编码(财务模块使用)
     */
    @Override
    public String getCodeBySupplierName(String supplierName) {
        return sysOrderSupplierManagementService.getCodeBySupplierName(supplierName);
    }

    /**
     * 更新供应商余额(财务模块使用)
     */
    @Override
    public boolean updateSupplierBalance(SysCustomerBalance customer) {
        return sysOrderSupplierManagementService.updateSupplierBalance(customer);
    }
}
